package com.yhf.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yhf.model.Contractor;
import com.yhf.model.Developer;
import com.yhf.model.Project;
import com.yhf.dto.ProjectOv;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;


@Repository
public interface PMapper extends BaseMapper<Project> {
    @Results(id = "projectresult1",value = {
            @Result(column = "pid",property = "pid"),
            @Result(column = "pname",property = "pname"),
            @Result(column = "starttime",property = "starttime"),
            @Result(column = "endtime",property = "endtime"),
            @Result(column = "status",property = "status"),
            @Result(column = "did",property = "did"),
            @Result(column = "cid",property = "cid"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "did",property = "developer",javaType = Developer.class,one =
            @One(select = "com.yhf.mapper.DeveloperMapper.selectById",fetchType = FetchType.EAGER)
            ),
            @Result(column = "cid",property = "contractor",javaType = Contractor.class,one =
            @One(select = "com.yhf.mapper.ConstractorMapper.selectById",fetchType = FetchType.EAGER)
            )
    })
    @Select("Select * from project ${ew.customSqlSegment}")
    IPage<ProjectOv> selectAll(Page<ProjectOv> page,@Param(Constants.WRAPPER) QueryWrapper<ProjectOv> queryWrapper);

    @ResultMap("projectresult1")
    @Select("Select * from project where pid = #{pid}")
    ProjectOv selectByPid(@Param("pid") Integer pid);
}
